/**
 *  This file is part of OhSnap.
 *
 * 	Copyright (c) 2009 Gabriel Mendonça and Marcelo Machado
 * 
 *  OhSnap is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OhSnap is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OhSnap.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */
package br.mm.ui;

import java.awt.Color;
import java.awt.Rectangle;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import br.mm.cg.OhSnap;

import com.bric.swing.ColorPicker;

/**
 * @author machado
 * 
 */

public class AlternativeMainScreen extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jPanel = null;
	private JLabel jLabelGenerator = null;
	private JLabel jLabelGenerator1 = null;
	private JTextField jTextFieldGeneratorMax = null;
	private JLabel jLabelGenerator2 = null;
	private JTextField jTextFieldParticleMax = null;
	private JLabel jLabelGenerator3 = null;
	private JTextField jTextFieldParticleMax1 = null;
	private JButton jButtonColor = null;
	private JLabel jLabelGenerator4 = null;
	private JTextField jTextFieldParticleSize = null;
	private JButton jButtonBrowse = null;
	private Color color; // @jve:decl-index=0:
	private JTabbedPane jTabbedPane = null;
	private JPanel jPanel1 = null;
	private JPanel jPanel2 = null;
	private JLabel jLabelExplosion = null;
	private JLabel jLabelExplosion2 = null;
	private JTextField jTextFieldExplosionRate = null;
	private JLabel jLabelExplosion1 = null;
	private JTextField jTextFieldExplosionIntensity = null;
	private JLabel jLabelGeneral = null;
	private JLabel jLabelGeneral1 = null;
	private JCheckBox jCheckBox3D = null;
	private JLabel jLabelGeneral2 = null;
	private JTextField jTextFieldFrameRate = null;
	private JLabel jLabelGeneral4 = null;
	private JTextField jTextFieldFile = null;
	private JButton jButtonRun = null;

	/**
	 * This is the default constructor
	 */
	public AlternativeMainScreen() {
		super();
		initialize();
	}

	public String getMidiFile() {
		return jTextFieldFile.getText();
	}
	
	/**
	 * @return
	 */
	public float[] getColor() {
		return new float[] {color.getRed(), color.getGreen(), color.getBlue()};
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(593, 273);
		this.setContentPane(getJTabbedPane());
		this.setTitle("Oh Snap!");
	}
	
	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabelGenerator4 = new JLabel();
			jLabelGenerator4.setBounds(new Rectangle(3, 103, 179, 21));
			jLabelGenerator4.setText("Tamanho das Partículas");
			jLabelGenerator3 = new JLabel();
			jLabelGenerator3.setBounds(new Rectangle(3, 135, 177, 18));
			jLabelGenerator3.setText("Raio de um Gerador");
			jLabelGenerator2 = new JLabel();
			jLabelGenerator2.setBounds(new Rectangle(4, 75, 179, 20));
			jLabelGenerator2.setText("Número máximo de Partículas");
			jLabelGenerator1 = new JLabel();
			jLabelGenerator1.setBounds(new Rectangle(4, 45, 178, 21));
			jLabelGenerator1.setText("Número máximo de Geradores");
			jLabelGenerator = new JLabel();
			jLabelGenerator.setBounds(new Rectangle(6, 13, 144, 24));
			jLabelGenerator.setText("Opções dos Geradores");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.add(jLabelGenerator, null);
			jPanel.add(jLabelGenerator1, null);
			jPanel.add(getJTextFieldGeneratorMax(), null);
			jPanel.add(jLabelGenerator2, null);
			jPanel.add(getJTextFieldParticleMax(), null);
			jPanel.add(jLabelGenerator3, null);
			jPanel.add(getJTextFieldParticleMax1(), null);
			jPanel.add(getJButtonColor(), null);
			jPanel.add(jLabelGenerator4, null);
			jPanel.add(getJTextFieldParticleSize(), null);
			color = new Color(120, 200, 160);

		}
		return jPanel;
	}

	/**
	 * This method initializes jTextFieldGeneratorMax
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextFieldGeneratorMax() {
		if (jTextFieldGeneratorMax == null) {
			jTextFieldGeneratorMax = new JTextField();
			jTextFieldGeneratorMax.setBounds(new Rectangle(192, 45, 39, 25));
			jTextFieldGeneratorMax.setText("5");
		}
		return jTextFieldGeneratorMax;
	}

	/**
	 * This method initializes jTextFieldParticleMax
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextFieldParticleMax() {
		if (jTextFieldParticleMax == null) {
			jTextFieldParticleMax = new JTextField();
			jTextFieldParticleMax.setBounds(new Rectangle(194, 76, 38, 23));
			jTextFieldParticleMax.setText("50");
		}
		return jTextFieldParticleMax;
	}

	/**
	 * This method initializes jTextFieldParticleMax1
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextFieldParticleMax1() {
		if (jTextFieldParticleMax1 == null) {
			jTextFieldParticleMax1 = new JTextField();
			jTextFieldParticleMax1.setBounds(new Rectangle(194, 133, 39, 24));
			jTextFieldParticleMax1.setText("50");
		}
		return jTextFieldParticleMax1;
	}

	/**
	 * This method initializes jButtonColor
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonColor() {
		if (jButtonColor == null) {
			jButtonColor = new JButton();
			jButtonColor.setBounds(new Rectangle(4, 168, 197, 29));
			jButtonColor.setText("Escolher cor dos Geradores");
			jButtonColor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					pickColor();
				}
			});
		}
		return jButtonColor;
	}

	/**
	 * This method initializes jTextFieldParticleSize
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getJTextFieldParticleSize() {
		if (jTextFieldParticleSize == null) {
			jTextFieldParticleSize = new JTextField();
			jTextFieldParticleSize.setBounds(new Rectangle(193, 103, 39, 25));
			jTextFieldParticleSize.setText("10");
		}
		return jTextFieldParticleSize;
	}

	/**
	 * This method initializes jButtonBrowse
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonBrowse() {
		if (jButtonBrowse == null) {
			jButtonBrowse = new JButton();
			jButtonBrowse.setText("Pesquisar");
			jButtonBrowse.setBounds(new Rectangle(457, 165, 106, 25));
			jButtonBrowse
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {

							browseFile();

						}
					});
		}
		return jButtonBrowse;
	}

	private void browseFile() {

		final JFileChooser fc = new JFileChooser();
		String name = new String();
		fc.addChoosableFileFilter(new MidiFilter());
		int returnVal = fc.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			name = file.getAbsolutePath();
		}

		jTextFieldFile.setText(name);

	}

	private void pickColor() {
		color = ColorPicker.showDialog(new JFrame(), color);
	}

	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.addTab("Configurações de Gerador", null, getJPanel(), null);
			jTabbedPane.addTab("Configurações de Explosões", null, getJPanel1(), null);
			jTabbedPane.addTab("Configurações Gerais", null, getJPanel2(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabelExplosion1 = new JLabel();
			jLabelExplosion1.setBounds(new Rectangle(10, 81, 154, 26));
			jLabelExplosion1.setText("Intensidade das Explosões");
			jLabelExplosion2 = new JLabel();
			jLabelExplosion2.setBounds(new Rectangle(9, 50, 154, 25));
			jLabelExplosion2.setText("Taxa de Explosões");
			jLabelExplosion = new JLabel();
			jLabelExplosion.setBounds(new Rectangle(8, 11, 151, 29));
			jLabelExplosion.setText("Opções das Explosões");
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.add(jLabelExplosion, null);
			jPanel1.add(jLabelExplosion2, null);
			jPanel1.add(getJTextFieldExplosionRate(), null);
			jPanel1.add(jLabelExplosion1, null);
			jPanel1.add(getJTextFieldExplosionIntensity(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jLabelGeneral4 = new JLabel();
			jLabelGeneral4.setBounds(new Rectangle(13, 166, 101, 23));
			jLabelGeneral4.setText("Arquivo Mid");
			jLabelGeneral2 = new JLabel();
			jLabelGeneral2.setBounds(new Rectangle(10, 111, 96, 31));
			jLabelGeneral2.setText("Frame Rate");
			jLabelGeneral1 = new JLabel();
			jLabelGeneral1.setBounds(new Rectangle(13, 63, 56, 31));
			jLabelGeneral1.setText("3D?");
			jLabelGeneral = new JLabel();
			jLabelGeneral.setBounds(new Rectangle(5, 7, 158, 28));
			jLabelGeneral.setText("Opções Gerais");
			jPanel2 = new JPanel();
			jPanel2.setLayout(null);
			jPanel2.add(jLabelGeneral, null);
			jPanel2.add(jLabelGeneral1, null);
			jPanel2.add(getJCheckBox3D(), null);
			jPanel2.add(jLabelGeneral2, null);
			jPanel2.add(getJTextFieldFrameRate(), null);
			jPanel2.add(jLabelGeneral4, null);
			jPanel2.add(getJTextFieldFile(), null);
			jPanel2.add(getJButtonBrowse(), null);
			jPanel2.add(getJButtonRun(), null);
		}
		return jPanel2;
	}

	/**
	 * This method initializes jTextFieldExplosionRate	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldExplosionRate() {
		if (jTextFieldExplosionRate == null) {
			jTextFieldExplosionRate = new JTextField();
			jTextFieldExplosionRate.setBounds(new Rectangle(171, 51, 36, 22));
			jTextFieldExplosionRate.setText("5");
		}
		return jTextFieldExplosionRate;
	}

	/**
	 * This method initializes jTextFieldExplosionIntensity	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldExplosionIntensity() {
		if (jTextFieldExplosionIntensity == null) {
			jTextFieldExplosionIntensity = new JTextField();
			jTextFieldExplosionIntensity.setBounds(new Rectangle(171, 82, 37, 23));
			jTextFieldExplosionIntensity.setText("5");
		}
		return jTextFieldExplosionIntensity;
	}

	/**
	 * This method initializes jCheckBox3D	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox3D() {
		if (jCheckBox3D == null) {
			jCheckBox3D = new JCheckBox();
			jCheckBox3D.setBounds(new Rectangle(138, 62, 25, 26));
		}
		return jCheckBox3D;
	}

	/**
	 * This method initializes jTextFieldFrameRate	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldFrameRate() {
		if (jTextFieldFrameRate == null) {
			jTextFieldFrameRate = new JTextField();
			jTextFieldFrameRate.setBounds(new Rectangle(130, 115, 51, 28));
			jTextFieldFrameRate.setText("5");
		}
		return jTextFieldFrameRate;
	}

	/**
	 * This method initializes jTextFieldFile	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldFile() {
		if (jTextFieldFile == null) {
			jTextFieldFile = new JTextField();
			jTextFieldFile.setBounds(new Rectangle(130, 166, 292, 27));
			jTextFieldFile.setText("data/canon.mid");
		}
		return jTextFieldFile;
	}

	/**
	 * This method initializes jButtonRun	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonRun() {
		if (jButtonRun == null) {
			jButtonRun = new JButton();
			jButtonRun.setBounds(new Rectangle(332, 14, 204, 122));
			jButtonRun.setText("Rodar!!!");
			jButtonRun.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					OhSnap.runAnimation();
				}
			});
		}
		return jButtonRun;
	}

}  //  @jve:decl-index=0:visual-constraint="104,-16"
